﻿namespace Zhp.Cache
{
    public interface ICacheService : IDisposable
    {
        #region 基本操作

        /// <summary>
        /// 不存在返回null
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key"></param>
        /// <returns></returns>
        T Get<T>(string key);

        /// <summary>
        /// 不存在返回null
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        Task<T> GetAsync<T>(string key, CancellationToken token = default);

        void Set<T>(string key, T value, TimeSpan? expire = null);

        Task SetAsync<T>(string key, T value, TimeSpan? expire = null, CancellationToken token = default);

        void Refresh(string key);

        Task RefreshAsync(string key, CancellationToken token = default);

        void Remove(string key);

        Task RemoveAsync(string key, CancellationToken token = default);

        void Remove(string[] keys);

        Task RemoveAsync(string[] keys, CancellationToken token = default);

        #endregion

        #region 集合操作

        List<T> ListRange<T>(string key);

        void ListRightPush<T>(string key, T value);

        void ListRightPushArray<T>(string key, T[] values);

        void ListRemove<T>(string key, T value);

        T ListLeftPop<T>(string key);

        #endregion

        #region 哈希对象操作

        T HashObjGet<T>(string key, string field);

        T HashObjGet<T>(string key);

        void HashObjSet<T>(string key, T value);

        void HashObjSet(string key, string hashField, object value);

        void HashObjDelete(string key);

        #endregion

        #region 哈希集合操作

        T HashListGet<T>(string key, object fieldId);

        List<T> HashListGetAll<T>(string key);

        void HashListSet<T>(string key, Func<T, object> fieldFunc, T value);

        void HashListSet<T>(string key, Func<T, object> fieldFunc, List<T> values);

        void HashListDelete(string key, string field);
        #endregion
    }
}
